// 集中管理项目【岗位】功能相关的所有异步请求
// 方便复用
// 便于维护
import request from "../utils/request";
//录入分类
export const categoryPost = (cateObj) => {
  return request.post("classes/category", cateObj);
};

// categoryPost  就是个方法函数
// categoryPost()  函数调用后，会得到什么类型的数据？是promise对象
// categoryPost().then()

//查询分类
export const categoryGet = (all) => {
  // 写法1:
  // return request.get(`classes/category?where={"parentId":"0-0"}`);
  // 写法2：
  let where = all ? {} : { parentId: "0-0" }; //根据categoryGet调用传递的参数，决定是否携带查询条件
  return request.get(`classes/category`, {
    params: {
      where,
    },
  });
};

//企业入驻
export const companyPost = (companyObj) => {
  return request.post("classes/company", companyObj);
};

//岗位列表

export const jobGet = (page = 1, search = {}) => {
  let skip = (page - 1) * 10;
  // 不要携带值为空的字段给后端
  for (let attr in search) {
    if (!search[attr]) {
      delete search[attr];
    }
  }
  if (search.jobName) {
    search.jobName = { $regex: search.jobName, $options: "i" }; //正则查询、模糊查询
  }
  return request.get("classes/job", {
    params: {
      limit: 10,
      count: 1, //计数
      skip,
      where: search,
    },
  });
};

//动态渲染图表
export const pieGet = () => {
  return request.get("classes/pie");
};
